a = {'zero': '0',
     'one': '1',
     'two': '2',
     'three': '3',
     'four': '4',
     'five': '5',
     'six': '6',
     'seven': '7',
     'eight': '8',
     'nine': '9'}


def prime(x):
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            return False
    return True


s = input().split()

if len(s) < 3:
    print('Wrong input')

st = ''
st += a[s[0]]
st += a[s[1]]
st += a[s[2]]
st = int(st)

c1 = 0+
c2 = 0
for i in range(st, 100, -1):
    if prime(i):
        c1 = i
        break
for i in range(st, 1000):
    if prime(i):
        c2 = i
        break
if (st - c1) > (c2 - st):
    print(c2)
else:
    print(c1)
